'use strict';

const path = require('path');
const egg = require('egg');
const {restful} = require('./restful');
const EGG_PATH = Symbol.for('egg#eggPath');
const EGG_LOADER = Symbol.for('egg#loader');

class Application extends egg.Application {
  get [EGG_PATH]() {
    return path.dirname(__dirname);
  }

  // 覆盖 Egg 的 Loader
  get [EGG_LOADER](){
    return ZijueAppWorkerLoader;
  }
}

class Agent extends egg.Agent {
  get [EGG_PATH]() {
    return path.dirname(__dirname);
  }
}

class ZijueAppWorkerLoader extends egg.AppWorkerLoader{
  constructor(opt){
    super(opt);
  }
  loadRouter(){
    // 在加载 router 前对 EggRouter 进行扩展
    this.app.router['restful'] = restful;
    // console.log(this.app.router.restful);
    super.loadRouter();
  }
}

module.exports = Object.assign(egg, {
  Application,
  Agent,
  AppWorkerLoader: ZijueAppWorkerLoader,
});
